package com.zhangtingshu.service.impl;

import com.zhangtingshu.dao.InvitationDao;
import com.zhangtingshu.pojo.Invitation;
import com.zhangtingshu.service.InvitationService;
import com.zhangtingshu.vo.ChartInfo;
import com.zhangtingshu.vo.InvitationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhangtingshu
 * 帖子业务逻辑实现类
 */
@Service
public class InvitationServiceImpl implements InvitationService {

    @Autowired
    private InvitationDao invitationDao;

    @Override
    public List<InvitationVO> findAll(String searchInfo) {
        return invitationDao.findAll(searchInfo);
    }

    @Override
    public List<InvitationVO> findPersonList(int uid) {
        return invitationDao.findPersonList(uid);
    }

    @Override
    public Invitation findById(int id) {
        return invitationDao.findById(id);
    }

    @Override
    public boolean insert(Invitation invitation) {
        invitation.setCreatedate(new Timestamp(System.currentTimeMillis()));//当前的时间
        return invitationDao.insert(invitation) > 0 ? true : false;
    }

    @Override
    public boolean delete(int[] arrays) {
        return invitationDao.delete(arrays) > 0 ? true : false;
    }

    @Override
    public boolean update(Invitation invitation) {
        return invitationDao.update(invitation) > 0 ? true : false;
    }

    @Override
    public List<ChartInfo> findStatPie() {
        return invitationDao.findStat();
    }

    @Override
    public Map<String, List> findStatBar() {
        Map<String, List> map = new HashMap<>();
        List<ChartInfo> list = invitationDao.findLikeStat();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (ChartInfo info : list) {
            names.add(info.getName());
            values.add(info.getValue());
        }
        map.put("names", names);
        map.put("values", values);
        return map;
    }

    @Override
    public void addLike(int id, int num) {
        invitationDao.addLike(id, num);
    }
}
